package com.myssm.mybatis.org.apache.ibatis.session;

import com.myssm.mybatis.org.apache.ibatis.configuration.Configuration;
import com.myssm.mybatis.org.apache.ibatis.configuration.XmlConfigBuilder;
import org.dom4j.DocumentException;

import java.io.InputStream;

//生成SqlSessionFactory实例对象
public class SqlSessionFactoryBuilder{

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {
         Configuration configuration=new Configuration();
         //解析mybatis-config文件到configuration
         XmlConfigBuilder xmlConfigBuilder=new XmlConfigBuilder(configuration);
         xmlConfigBuilder.parseMyBatisConfig(inputStream);

         DefaultSqlSessionFactory defaultSqlSessionFactory=new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
